package com.lovo.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.system.dto.JournalDto;
import com.lovo.system.dto.PageDto;
import com.lovo.system.dto.PurchaseMesDto;
import com.lovo.system.service.IJournalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("/journal")
public class JournalController {

    @Autowired
    IJournalService journalService;

    @RequestMapping("/info")
    public IPage<JournalDto> info(@RequestBody PageDto<PurchaseMesDto> pageDto){
        return journalService.cutByItem(pageDto.getCurPage(),pageDto.getPageSize(),pageDto.getStartTime(),pageDto.getEndTime());
    }

    @RequestMapping("/add")
    public void insertJournal(HttpServletRequest request,String mes){
        JournalDto journalDto = new JournalDto();
        journalDto.setJournalDate(LocalDate.now());
        journalDto.setJournalContent(request.getSession().getAttribute("realName")+mes);
        journalService.insertJournal(journalDto);
    }

}
